# Copyright 2012 Sergio, Raul, Dorival. All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.

PROJECT                (GEMLAB)
CMAKE_MINIMUM_REQUIRED (VERSION 2.8)
ENABLE_TESTING         ()

# Flags
OPTION(A_MAKE_VERBOSE       "Show additional messages during compilation/link?" OFF)
OPTION(A_MAKE_ALL_WARNINGS  "Make with all warnings (-Wall)"                    OFF)
OPTION(A_MAKE_DEBUG_SYMBOLS "Make with debug symbols (-g)"                      OFF)
OPTION(A_MAKE_PROFILING     "Make with profiling information (-pg)"             OFF)
OPTION(A_MAKE_OPTIMIZED     "Make optimized (-O3)"                              OFF)
OPTION(A_MAKE_STATIC        "Make static library"                               OFF)

# needed when building Debian package
IF(NOT INSTALL_ROOT)
	SET(INSTALL_ROOT /)
ENDIF(NOT INSTALL_ROOT)

ADD_DEFINITIONS     (-fmessage-length=0) # Each error message will appear on a single line; no line-wrapping will be done.
INCLUDE_DIRECTORIES (${GEMLAB_SOURCE_DIR})

### FLAGS ###############################################################################################

IF(A_MAKE_VERBOSE)
	SET(CMAKE_VERBOSE_MAKEFILE TRUE)
ENDIF(A_MAKE_VERBOSE)

IF(A_MAKE_ALL_WARNINGS)
	ADD_DEFINITIONS(-Wall)
ENDIF(A_MAKE_ALL_WARNINGS)

IF(A_MAKE_DEBUG_SYMBOLS)
	ADD_DEFINITIONS(-g)
ENDIF(A_MAKE_DEBUG_SYMBOLS)

IF(A_MAKE_PROFILING)
	SET(CMAKE_CXX_FLAGS -pg)
ENDIF(A_MAKE_PROFILING)

IF(A_MAKE_OPTIMIZED)
	ADD_DEFINITIONS(-O3)
ENDIF(A_MAKE_OPTIMIZED)

### DEPENDENCIES ########################################################################################

SET(FLAGS "")
SET(LIBS "")
SET(LFFLAGS "")

# VTK
INCLUDE(FindVTK)
INCLUDE_DIRECTORIES(${VTK_INCLUDE_DIRS})
SET(LIBS  ${LIBS} vtkRendering vtkHybrid)
SET(FLAGS "${FLAGS} -DVTK_EXCLUDE_STRSTREAM_HEADERS")

# CGAL
INCLUDE(FindCGAL)
INCLUDE(${CGAL_USE_FILE})

# Eigen3
INCLUDE(${GEMLAB_SOURCE_DIR}/Modules/FindEIGEN3.cmake)
INCLUDE_DIRECTORIES(${EIGEN3_INCLUDE_DIRS})

# MPI
INCLUDE(FindMPI)
INCLUDE_DIRECTORIES (${MPI_INCLUDE_PATH})
SET(FLAGS  "${FLAGS}  ${MPI_COMPILE_FLAGS}")
SET(LIBS    ${LIBS}   ${MPI_LIBRARIES})
SET(LFLAGS "${LFLAGS} ${MPI_LINK_FLAGS}")

# Parmetis
INCLUDE(${GEMLAB_SOURCE_DIR}/Modules/FindPARMETIS.cmake)
INCLUDE_DIRECTORIES(${PARMETIS_INCLUDE_DIRS})
SET(LIBS ${LIBS} ${PARMETIS_LIBRARIES})


### LIBRARIES ###########################################################################################

SET(LIBFILES triangle.c tetgen_predicates.cpp tetgen.cpp)
ADD_DEFINITIONS(-Wno-unused-result)
IF(A_MAKE_STATIC)
    ADD_LIBRARY(gemlab STATIC ${LIBFILES})
ELSE(A_MAKE_STATIC)
    ADD_LIBRARY(gemlab SHARED ${LIBFILES})
ENDIF(A_MAKE_STATIC)

SET(LIBS ${LIBS} -lgemlab)
INCLUDE_DIRECTORIES(${GEMLAB_SOURCE_DIR})
LINK_DIRECTORIES(${GEMLAB_SOURCE_DIR})

### EXAMPLES ############################################################################################

SUBDIRS(examples)

### TESTS ###############################################################################################

SUBDIRS(tests)

### TOOLS ###############################################################################################
